import Vue from 'vue'
import Router from 'vue-router'
import Abstract from '../components/abstruct.vue'
Vue.use(Router)

let baseRoute = [{
  path: '/base',
  name: '基础设置',
  component: Abstract,
  children: [{
    path: 'canteen',
    name: '食堂',
    component: (resolve) => require(['../views/base/canteen'], resolve)
  }, {
    path: 'card',
    name: '卡务中心',
    component: (resolve) => require(['../views/base/card'], resolve)
  }, {
    path: 'staff',
    name: '员工',
    component: (resolve) => require(['../views/base/staff'], resolve)
  }, {
    path: 'periods',
    name: '餐别',
    component: (resolve) => require(['../views/base/periods'], resolve)
  }, {
    path: 'stalls',
    name: '档口',
    component: (resolve) => require(['../views/base/stalls'], resolve)
  }, {
    path: 'chef',
    name: '厨师',
    component: (resolve) => require(['../views/base/chef'], resolve)
  }, {
    path: 'tableware',
    name: '餐具',
    component: (resolve) => require(['../views/base/tableware'], resolve)
  }, {
    path: 'categoryc',
    name: '品类',
    component: (resolve) => require(['../views/base/categoryc'], resolve)
  }, {
    path: 'item',
    name: '单品',
    component: (resolve) => require(['../views/base/item'], resolve)
  }, {
    path: 'shortcut',
    name: '快捷菜品',
    component: (resolve) => require(['../views/base/shortcut'], resolve)
  }, {
    path: 'deposit',
    name: '卡押金',
    component: (resolve) => require(['../views/base/deposit'], resolve)
  }, {
    path: 'cardtype',
    name: '卡类型',
    component: (resolve) => require(['../views/base/cardtype'], resolve)
  }, {
    path: 'customer',
    name: '食客类别',
    component: (resolve) => require(['../views/base/customer'], resolve)
  }, {
    path: 'address',
    name: '送餐地址',
    component: (resolve) => require(['../views/base/address'], resolve)
  }]
}, {
  path: '/card',
  name: '卡务管理',
  component: Abstract,
  children: [{
    path: 'open',
    name: '开卡',
    component: (resolve) => require(['../views/card/open'], resolve)
  }, {
    path: 'manager',
    name: '卡管理',
    component: (resolve) => require(['../views/card/manager'], resolve)
  }, {
    path: 'list',
    name: '卡列表',
    component: (resolve) => require(['../views/card/list'], resolve)
  }, {
    path: 'recharge',
    name: '批量充值导入',
    component: (resolve) => require(['../views/card/recharge'], resolve)
  }, {
    path: 'rechargelog',
    name: '批量充值日志',
    component: (resolve) => require(['../views/card/rechargelog'], resolve)
  }, {
    path: 'subsidy',
    name: '批量补贴导入',
    component: (resolve) => require(['../views/card/subsidy'], resolve)
  }, {
    path: 'subsidylog',
    name: '批量补贴日志',
    component: (resolve) => require(['../views/card/subsidylog'], resolve)
  }]
}, {
  path: '/setting',
  name: '高级设置',
  component: Abstract,
  children: [{
    path: 'strategy',
    name: '补贴策略',
    component: (resolve) => require(['../views/setting/strategy'], resolve)
  }, {
    path: 'discount',
    name: '消费优惠策略',
    component: (resolve) => require(['../views/setting/discount'], resolve)
  }, {
    path: 'limit',
    name: '消费限制策略',
    component: (resolve) => require(['../views/setting/limit'], resolve)
  }, {
    path: 'sequence',
    name: '按次消费限制策略',
    component: (resolve) => require(['../views/setting/sequence'], resolve)
  }, {
    path: 'canteen',
    name: '食堂高级设置',
    component: (resolve) => require(['../views/setting/canteen'], resolve)
  }, {
    path: 'card',
    name: '卡务高级设置',
    component: (resolve) => require(['../views/setting/card'], resolve)
  }, {
    path: 'uplinit',
    name: '消费上限策略',
    component: (resolve) => require(['../views/setting/uplimit'], resolve)
  }]
}, {
  path: '/product',
  name: '生产管理',
  component: Abstract,
  children: [{
    path: 'menu',
    name: '菜谱计划',
    component: (resolve) => require(['../views/product/menu'], resolve)
  }]
}, {
  path: '/others',
  name: '其他',
  component: Abstract,
  children: [{
    path: 'items',
    name: '单品评价',
    component: (resolve) => require(['../views/others/items'], resolve)
  }, {
    path: 'windows',
    name: '档口评价',
    component: (resolve) => require(['../views/others/windows'], resolve)
  }]
}]

let router = new Router({
  routes: baseRoute,
  mode: 'history'
})
// 路由守卫
router.beforeEach((to, from, next) => {
  let routeName = to.meta.name || to.name
  window.document.title = routeName
  next()
})
export default router
